package saeildamil.Ch18.communication;

import javax.swing.JOptionPane;

public class PrintPiThread extends Thread {
	SharedArea sharedArea;

	public PrintPiThread(SharedArea sharedArea) {
		this.sharedArea = sharedArea;
	}
	
	@Override
	public void run() {
		if(sharedArea.isReady != true){		//Pi 가 나오지 않는다면.
			synchronized (sharedArea) {
				try {
					JOptionPane.showMessageDialog(null, "원주율(Pi)이 계산될 때 까지 대기");
					sharedArea.wait();		// notify()가 올때까지 대기.
				} catch (InterruptedException e) {
					System.out.println(e.getMessage());
				}
			}
		} // end of if
		JOptionPane.showMessageDialog(null, "Pi 결과 : " + sharedArea.result);
	}

}
